//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package utils.io;

import business.Constants;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Properties;

public class PropertyFile {
    private Properties property;
    private String filePath;

    public PropertyFile() throws UnsupportedEncodingException {
        this("/conf/config.properties");
    }

    public PropertyFile(String propertyFileName) throws UnsupportedEncodingException {
        InputStream is = null;
        this.property = new Properties();
        this.filePath = URLDecoder.decode(Constants.getAbsPath() + propertyFileName, "UTF-8");

        try {
            is = new FileInputStream(this.filePath);
            this.property.load(is);
        } catch (IOException var12) {
            var12.printStackTrace();
        } finally {
            try {
                is.close();
            } catch (IOException var11) {
                var11.printStackTrace();
            }

        }

    }

    public PropertyFile(String propertyFilePath, String propertyFileName) throws UnsupportedEncodingException {
        InputStream is = null;
        this.property = new Properties();
        this.filePath = URLDecoder.decode(propertyFilePath + propertyFileName, "UTF-8");

        try {
            is = new FileInputStream(this.filePath);
            this.property.load(is);
        } catch (IOException var13) {
            var13.printStackTrace();
        } finally {
            try {
                is.close();
            } catch (IOException var12) {
                var12.printStackTrace();
            }

        }

    }

    public String read(String key) {
        return this.property.getProperty(key);
    }

    public void write(String key, String value) {
        FileInputStream is = null;

        label160: {
            try {
                is = new FileInputStream(this.filePath);
                this.property.clear();
                this.property.load(is);
                break label160;
            } catch (IOException var30) {
                var30.printStackTrace();
            } finally {
                try {
                    is.close();
                } catch (IOException var27) {
                    var27.printStackTrace();
                }

            }

            return;
        }

        OutputStream os = null;
        this.property.setProperty(key, value);

        try {
            os = new FileOutputStream(this.filePath);
            this.property.store(os, "");
            os.flush();
        } catch (Exception var28) {
            var28.printStackTrace();
        } finally {
            try {
                os.close();
            } catch (IOException var26) {
                var26.printStackTrace();
            }

        }

    }
}
